package io.github.definitlyevil.ziminmod;

import de.slikey.effectlib.EffectManager;
import io.github.definitlyevil.cifaddon.blockentity.advfurnace.recipe.AdvancedFurnaceCIFInputRecipe;
import io.github.definitlyevil.cifaddon.blockentity.advfurnace.recipe.AdvancedFurnaceRecipeRegister;
import io.github.definitlyevil.customitemframework.CIFItemInstance;
import io.github.definitlyevil.customitemframework.ItemRegister;
import io.github.definitlyevil.customitemframework.crafting.RecipeRegister;
import io.github.definitlyevil.customitemframework.crafting.ingredient.CIFCraftingIngredient;
import io.github.definitlyevil.customitemframework.crafting.ingredient.VanillaCraftingIngredient;
import io.github.definitlyevil.customitemframework.crafting.recipe.CIFRecipe;
import io.github.definitlyevil.ziminmod.cif.ZiMinOre;
import io.github.definitlyevil.ziminmod.cif.armors.*;
import io.github.definitlyevil.ziminmod.cif.tools.ZiMinPickaxe;
import io.github.definitlyevil.ziminmod.cif.tools.ZiMinSword;
import io.github.definitlyevil.ziminmod.listeners.*;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public final class ZiMinMod extends JavaPlugin {

    private static ZiMinMod instance;

    public static ZiMinMod getInstance() {
        return instance;
    }

    public static final String LORE_SEPARATOR_LINE = "\u00a78==================";

    private EffectManager effectManager;

    @Override
    public void onLoad() {
        instance = this;
    }

    @Override
    public void onEnable() {
        // 籽岷mod
        registerItems();
        registerRecipes();

        effectManager = new EffectManager(this);

        getServer().getPluginManager().registerEvents(new ZiMinSwordListener(), this);
        getServer().getPluginManager().registerEvents(new ZiMinPickaxeListener(), this);
        getServer().getPluginManager().registerEvents(new ZiMinChestplateListener(), this);
        getServer().getPluginManager().registerEvents(new ZiMinHelmetListener(), this);
        getServer().getPluginManager().registerEvents(new ZiMinLeggingsListener(), this);
    }

    private void registerItems() {
        ItemRegister.register(new ZiMinOre());
        ItemRegister.register(new ZiMinIngot());
        ItemRegister.register(new ZiMinSword());
        ItemRegister.register(new ZiMinPickaxe());

        ItemRegister.register(new ZiMinHelmet());
        ItemRegister.register(new ZiMinChestplate());
        ItemRegister.register(new ZiMinLeggings());
        ItemRegister.register(new ZiMinBoots());
        ItemRegister.register(new ZiMinGreenHat());
    }

    private void registerRecipes() {
        // 籽岷矿烧制成籽岷锭
        AdvancedFurnaceRecipeRegister.register(new AdvancedFurnaceCIFInputRecipe(
            "zimin_ore_to_zimin_ingot",
            new CIFItemInstance(ItemRegister.get("ZiMinOre"), null),
            ItemRegister.get("ZiMinIngot").generateItemStack(null, false),
            false,
            100
        ));

        // 针男人剑
        {
            CIFRecipe sword = new CIFRecipe(
                "zimin_sword",
                ItemRegister.get("ZiMinSword").generateItemStack(null, false),
                " z ",
                " z ",
                " z ",
                "izi",
                " d "
            );
            sword.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            sword.setIngredient('i', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("Steel"))));
            sword.setIngredient('d', new VanillaCraftingIngredient(new ItemStack(Material.DIAMOND)));
            RecipeRegister.register(sword);
        }

        // 针男人镐
        {
            CIFRecipe pickaxe = new CIFRecipe(
                "zimin_pickaxe",
                ItemRegister.get("ZiMinPickaxe").generateItemStack(null, false),
                "zzz",
                " d ",
                " d "
            );
            pickaxe.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            pickaxe.setIngredient('d', new VanillaCraftingIngredient(new ItemStack(Material.DIAMOND)));
            RecipeRegister.register(pickaxe);
        }

        // 针男人头盔
        {
            CIFRecipe r = new CIFRecipe(
                "zimin_helmet",
                ItemRegister.get("ZiMinHelmet").generateItemStack(null, false),
                "zzzzz",
                "z   z"
            );
            r.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            RecipeRegister.register(r);
        }

        // 针男人胸甲
        {
            CIFRecipe r = new CIFRecipe(
                "zimin_chestplate",
                ItemRegister.get("ZiMinChestplate").generateItemStack(null, false),
                "z   z",
                "zzzzz",
                "zzzzz"
            );
            r.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            RecipeRegister.register(r);
        }

        // 针男人裤头
        {
            CIFRecipe r = new CIFRecipe(
                "zimin_leggings",
                ItemRegister.get("ZiMinLeggings").generateItemStack(null, false),
                "zzzzz",
                "zs sz",
                "zz zz"
            );
            r.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            r.setIngredient('s', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("Steel"))));
            RecipeRegister.register(r);
        }

        // 针男人鞋头
        {
            CIFRecipe r = new CIFRecipe(
                "zimin_boots",
                ItemRegister.get("ZiMinBoots").generateItemStack(null, false),
                " z z ",
                " z z ",
                "zz zz"
            );
            r.setIngredient('z', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("ZiMinIngot"))));
            RecipeRegister.register(r);
        }
    }

    public EffectManager getEffectManager() {
        return effectManager;
    }
}
